import type { ProcessBlock, BlockProcessor, PreBlock, Row } from '../types';

const isBlockBegin = ({ value }: Row) => /^-{3,}/.test(value) || /^={3,}/.test(value) || /^_{3,}/.test(value);

const processBlock: ProcessBlock = (pbs) => {
  const result: PreBlock[] = [];
  for (const block of pbs) {
    if (block.type == 'row') {
      if (isBlockBegin(block)) {
        result.push({ type: 'hr' });
        continue;
      }
    }
    result.push(block);
  }
  return result;
};

const horizentalRuleProcessor: BlockProcessor = {
  isBlockBegin,
  process: processBlock,
};

export default {
  processor: horizentalRuleProcessor,
};
